package com.cc8w.home.controller;


import com.cc8w.entity.UserEntity;
import com.cc8w.home.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/home/index")
@Validated
public class IndexController {

    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String index(){
        return "index";
    }



    @RequestMapping("/getuser")
    @ResponseBody()
    public UserEntity getUser(@RequestParam(value="user_name",defaultValue = "") String userName){

        UserEntity userPojo = userService.queryUserByUserName(userName);

        //DateFormat bf = new SimpleDateFormat("yyyy-MM-dd E a HH:mm:ss");//时间格式化
        //System.out.println(bf.format(userPojo.getCreateTime()));

        return userPojo;
    }
    @RequestMapping("/getuser1")
    @ResponseBody()
    public UserEntity getUser1(@RequestParam(value="user_name",defaultValue = "") String userName){

        //带缓存-没有考虑并发
        UserEntity userPojo = userService.queryUserByName(userName);

        return userPojo;
    }

    @RequestMapping("/getuser2")
    @ResponseBody()
    public UserEntity getUser2(@RequestParam(value="user_name",defaultValue = "") String userName){
        //带缓存-考虑并发
        UserEntity userPojo = userService.queryUserByUname(userName);
        return userPojo;
    }

}
